package com.example.myapplication.tack_19;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_19.data.DetailData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import org.w3c.dom.Comment;

public class DetailsActivity extends AppCompatActivity {
    private ImageView exit;
    private ImageView imags;
    private TextView name;
    private TextView playDate;
    private TextView favoriteNum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_19_activity_details);
        init();
        exit_();
        Intent intent = getIntent();
        String id = intent.getStringExtra(Common.COMMON);
        getDerails(id);
    }

    private void getDerails(String id) {
        String url = "prod-api/api/movie/film/preview/"+id;
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, DetailData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                DetailData data = (DetailData)obj;
                if(data.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if("1".equals(id)){
                                name.setText("变形金刚");
                                playDate.setText("2021-04-08");
                                favoriteNum.setText("");
                            }else if(!id.equals("1")){
                                Glide.with(DetailsActivity.this).load(OkHttpTool.URL+data.getData().getCover()).into(imags);
                                name.setText(data.getData().getName());
                                playDate.setText(data.getData().getPlayDate());
                                String s = Html.fromHtml(data.getData().getIntroduction()).toString();
                                favoriteNum.setText(s);
                            }
                        }
                    });
                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DetailsActivity.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        imags = findViewById(R.id.imags);
        name = findViewById(R.id.name);
        playDate = findViewById(R.id.playDate);
        favoriteNum = findViewById(R.id.favoriteNum);
    }
}